package com.huang.bq;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/*
*   方式    抛出异常   有返回值，不抛出异常   阻塞 等待    超时等待
    添加    add      offer()            put()      offer(,,)
    移除   remove    poll()            take()     poll(,)
检测队首元素 element   peek                -          -

*
*
*
* */
public class Test {
    public static void main(String[] args) throws InterruptedException {
   //Collection
        //List
        //set
        //Queue
            //BlockQueue
        t1();

    }

    public static void t1() throws InterruptedException {

        /*
         *
         * 同步队列
         * 和其他的BlockingQueue 不一样， SynchronousQueue 不存储元素
         * put了一个元素，必须从里面先take取出来，否则不能在put进去值！
         *
         */
        ArrayBlockingQueue blockingQueue = new ArrayBlockingQueue<>(3);
//        System.out.println(blockingQueue.add("a"));
//        System.out.println(blockingQueue.add("b"));
//        System.out.println(blockingQueue.add("c"));
//
//        System.out.println("------------");
//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());


        System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));
        System.out.println("-----------");
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll(2, TimeUnit.SECONDS));

    }
}
